#include <iostream>
#include <vector>
using namespace std;

int pre[25],in[25],n;
struct Node{
    int data;
    struct Node *left,*right;
};
vector<Node*> v;
vector<int> ans;

Node *build(int l1,int r1,int l2,int r2){
    if(l2>r2)return NULL;
    Node *node = new Node;
    node->data = pre[l1];
    int index = l2;
    while(in[index]!=node->data)index++;
    int len = index-l2;
    node->left = build(l1+1,l1+len,l2,index-1);
    node->right = build(l1+len+1,r1,index+1,r2);
    return node;
}

signed main()
{
    cin>>n;
    for(int i=0;i<n;i++)    cin>>in[i];
    for(int i=0;i<n;i++)    cin>>pre[i];
    Node *root = build(0,n-1,0,n-1);
    cout<<root->data;
    v.push_back(root);
    while(!v.empty()){
        vector<Node*> t;
        for(int i=0;i<v.size();i++){
            if(v[i]->left)    t.push_back(v[i]->left);
            if(v[i]->right)    t.push_back(v[i]->right);
        }
        v = t;
        if(t.size())    cout<<" "<<t[0]->data;
    }
    return 0;
}
